package cn.itcast.mapper;

import cn.itcast.dao.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DeptMapper {
    @Select("select * from ss_dept")
    @Results({
            @Result(id = true, column = "dept_id", property = "id"),
            @Result(column = "dept_name", property = "deptName"),
            @Result(property = "parent", javaType = Dept.class, column = "parent_id",
                    one = @One(select = "cn.itcast.mapper.DeptMapper.findById"))
    })
    List<Dept> findAll();

    @Select("select * from ss_dept where dept_id=#{pid}")
    @Results({
            @Result(id = true, column = "dept_id", property = "id"),
            @Result(column = "dept_name", property = "deptName"),
            @Result(property = "parent", javaType = Dept.class, column = "parent_id",
                    one = @One(select = "cn.itcast.mapper.DeptMapper.findById"))
    })
   Dept findById(String pid);

    @Insert("insert into ss_dept (dept_id, dept_name, parent_id,state)\n" +
            "        values (#{id,jdbcType=VARCHAR}, #{deptName,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR},#{state,jdbcType=DECIMAL})")
    @Results({
            @Result(id = true, column = "dept_id", property = "id"),
            @Result(column = "dept_name", property = "deptName"),
            @Result(property = "parent", javaType = Dept.class, column = "parent_id",
                    one = @One(select = "cn.itcast.mapper.DeptMapper.findById"))
    })
    void edit(Dept dept);
}
